//
//  WBVisitorView.swift
//  weibo
//
//  Created by Felix on 16/11/6.
//  Copyright © 2016年 Felix. All rights reserved.
//

import UIKit

class WBVisitorView: UIView {

    
    

    @IBOutlet var rotationImageView: UIImageView!
    
    
    @IBOutlet var iconImageView: UIImageView!
    
    
    @IBOutlet var titleLabel: UILabel!
    
   
    @IBOutlet var registerButton: UIButton!
    
    @IBOutlet var loginButton: UIButton!
    
    
    func setUpVisitorViewInfo(imageName:String? , title:String){
        
        guard let name = imageName else {
            
            //开启动画
            startAnimation()
            //首页 不需要设置
            return
        }
        rotationImageView.isHidden = true
        
        iconImageView.image = UIImage.init(named: name)
        
        titleLabel.text = title;
        
    }
    
    
    //MARK:- 动画
    private func startAnimation(){
        let  animation  =  CABasicAnimation.init(keyPath: "transform.rotation")
        
        animation.toValue = 2 * M_PI
        animation.duration = 5.0
        
        animation.repeatCount = MAXFLOAT;
        //开启这个系统在视图失去焦点时候才不会停止动画
        animation.isRemovedOnCompletion = false
        
        rotationImageView.layer.add(animation, forKey: nil)
        
    }
    
    
    
    ///返回访客视图
    class func visitor() -> WBVisitorView{
        return Bundle.main.loadNibNamed("WBVisitorView", owner: nil, options: nil)?.last as! WBVisitorView
    }
    
    
    
}
